//
//  LoginViewController.m
//  RegularExpressionsDemo
//
//  Created by My Mac on 2017/5/31.
//  Copyright © 2017年 MyMac. All rights reserved.
//

#import "LoginViewController.h"

@interface LoginViewController ()
{
    __weak IBOutlet UITextField *countField;
    __weak IBOutlet UITextField *passwordField;
}
@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"使用正则表达式登录信息";
}

- (IBAction)loginAction:(UIButton *)sender {
    //count:手机号/邮箱
    if ([countField.text validatePhone] | [countField.text isValidEmail]) {
        NSLog(@"Count通过");
        //password:由数字、符号、字母组成的字符串
        if([passwordField.text validatePassword]){
            [self setShowAlertMsg:@"登录成功"];
        } else {
            [self setShowAlertMsg:@"密码错误"];
        }
    } else {
        [self setShowAlertMsg:@"账号无效"];
    }
}

//设置警告框
- (void)setShowAlertMsg:(NSString *)msg
{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alert animated:YES completion:nil];
}

@end
